package tenthwork.two;

/**
 * @author ：chenzikang
 * @date ： 2020/4/22
 */

class MyThread extends Thread {

    // 表示线程的名称
    private String name;

    // 通过构造方法配置name属性
    public MyThread(String name) {
        this.name = name;
    }


    public void run() {

        for (int i = 0; i < 6; i++) {
            try {
                // 线程休眠
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
            System.out.println(name + "运行，i = " + i);
        }


    }


}


public class RunnableDemo {
    public static void main(String args[]) {
        MyThread mt1 = new MyThread("线程A ");    // 实例化对象
        MyThread mt2 = new MyThread("线程B ");    // 实例化对象
        MyThread mt3 = new MyThread("线程C ");
        mt1.start();   // 调用线程主体
        mt2.start();   // 调用线程主体
        mt3.start();
    }

}
